package com.googlecode.cswish.struts;

import com.googlecode.cswish.util.FrameConstant;

/**
 * Describe a invoker command
 * 
 * @author jerry.feng Date: 2008-9-25
 */
public class Invoker {
	public static final String DEFAULT_METHOD = "execute";
	
	public String actionName;
	public String methodName;
	public char separator;
	
	public Invoker(String actionName) {
		this.actionName = actionName;
	}
	
	public Invoker(String actionName, char separator, String methodName) {
		this.actionName = actionName;
		this.separator = separator;
		this.methodName = methodName;
	}
	
	public boolean isInputMethod() {
		return methodName != null && methodName.startsWith(FrameConstant.ACTION_PREPARE);
	}

	/**
	 * Please call isInputMethod() before calling this method
	 * 
	 * @return input method name
	 */
	public String getInputMethod() {
		return FrameConstant.ACTION_PREPARE + methodName;
	}
	public String getSubmitMethod() {
		if (isInputMethod()) {
			return methodName.substring(FrameConstant.ACTION_PREPARE.length());
		} else {
			return methodName;
		}
	}
	
	public String toString() {
		return actionName;
	}
	
	public Invoker clone() {
		return new Invoker(this.actionName, this.separator, this.methodName);
	}
}